package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.dto.PageDto;
import com.qf.mapper.DtsCouponUserMapper;
import com.qf.pojo.DtsCouponUser;
import com.qf.service.DtsCouponUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project E-commercebackGroundManagementSystem
 * @date 2022/9/25 11:31
 */
@Service
public class DtsCouponUserServiceImpl implements DtsCouponUserService {
    @Autowired
    private DtsCouponUserMapper dtsCouponUserMapper;
    @Override
    public Page<DtsCouponUser> selectPage(PageDto pageDto) {
        ////http://localhost:8080/admin/coupon/listuser?page=1&limit=20&couponId=11&userId=ffff&status=1&sort=add_time&order=desc
        return dtsCouponUserMapper.selectPage(new Page<DtsCouponUser>(pageDto.getPage(), pageDto.getLimit()),new QueryWrapper<DtsCouponUser>().orderBy
                (!StringUtils.isEmpty(pageDto.getSort()), "asc".equalsIgnoreCase(pageDto.getOrder()), pageDto.getSort())
                .eq(pageDto.getStatus()!=null,"status",pageDto.getStatus()).eq(pageDto.getUserId()!=null,"user_id",pageDto.getUserId())
        .eq(pageDto.getCouponId()!=null,"coupon_id",pageDto.getCouponId()).eq("deleted",false));
    }
}
